package edu.sias.hyzn.service.impl;

import edu.sias.common.utils.SecurityUtils;
import edu.sias.hyzn.domain.Medicine;
import edu.sias.hyzn.domain.MedicineRecord;
import edu.sias.hyzn.mapper.MedicineMapper;
import edu.sias.hyzn.service.IMedicineService;
import edu.sias.hyzn.vo.MedicineRecordPie;
import edu.sias.hyzn.vo.MedicineRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MedicineService implements IMedicineService {

    private final MedicineMapper medicineMapper;

    @Autowired
    public MedicineService(MedicineMapper medicineMapper) {
        this.medicineMapper = medicineMapper;
    }

    @Override
    public List<Medicine> selectMedicineList(Medicine medicine) {
        return medicineMapper.selectMedicineList(medicine);
    }

    @Override
    public List<MedicineRecordVO> selectMedicineRecordVOList() {
        Long userId = SecurityUtils.getUserId();
        return medicineMapper.selectMedicineRecordVOList(userId);
    }

    @Override
    public int insertMedicine(Medicine medicine) {
        return medicineMapper.insertMedicine(medicine);
    }

    @Override
    public int updateMedicine(Medicine medicine) {
        return medicineMapper.updateMedicine(medicine);
    }

    @Override
    public int deleteMedicineById(Long id) {
        return medicineMapper.deleteMedicineById(id);
    }

    @Override
    public int insertMedicineRecord(MedicineRecord medicineRecord) {
        Long user_id = SecurityUtils.getUserId();
        medicineRecord.setUserId(user_id);
        return medicineMapper.insertMedicineRecord(medicineRecord);
    }

    @Override
    public int updateMedicineRecord(MedicineRecord medicineRecord) {
        return medicineMapper.updateMedicineRecord(medicineRecord);
    }

    @Override
    public int deleteMedicineRecordById(Long id) {
        return medicineMapper.deleteMedicineRecordById(id);
    }

    @Override
    public List<MedicineRecordPie> selectMedicineRecordVOById(Long userId) {
        return medicineMapper.selectMedicineRecordGroupByMedicine(userId);
    }
}
